/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:22:55 AM
------------------------------------------------------*/
using hou_elearning.DataAccess.Base;
using hou_elearning.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;

namespace hou_elearning.DataAccess
{    
    public class QuyenDAL : SqlProvider<QuyenEntity>
    {
        static QuyenDAL()
        {
            InitReader();
        }
        protected static void InitReader()
        {
            getFromReader=delegate(SqlDataReader dr)
            {
                QuyenEntity entity = new QuyenEntity();
				entity.PK_iQuyenID = Int16.Parse("0"+dr["PK_iQuyenID"].ToString());
				entity.sTenquyen = dr["sTenquyen"].ToString();
				entity.sTenviettat = dr["sTenviettat"].ToString();
				entity.sGhichu = dr["sGhichu"].ToString();
                return entity;
            };
        }
        public static QuyenEntity GetOne(Int16 PK_iQuyenID)
        {
            string cmdName = "spQuyen_GetByPK";
            SqlParameter p = new SqlParameter("@PK_iQuyenID", PK_iQuyenID);
            QuyenEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static List<QuyenEntity> GetAll()
        {
            string cmdName = "spQuyen_Get";
            return GetList(cmdName);
        }
        
        public static int Add(QuyenEntity entity)
        {
            string cmdName = "spQuyen_Insert";
            return Run(cmdName,true,initParams(entity));

        }
        public static bool Edit(QuyenEntity entity)
        {
            string cmdName = "spQuyen_Update";
            return Run(cmdName,false,initParams(entity))>0;
        }
        public static bool Remove(Int16 PK_iQuyenID)
        {
            string cmdName = "spQuyen_Delete";
            SqlParameter p = new SqlParameter("@PK_iQuyenID", PK_iQuyenID);
            return Run(cmdName,false,p)>0;
        }
        #region private
        private static SqlParameter[] initParams(QuyenEntity entity)
        {
            SqlParameter[] p = new SqlParameter[4];
			p[0] = new SqlParameter("@PK_iQuyenID", entity.PK_iQuyenID);
			p[1] = new SqlParameter("@sTenquyen", entity.sTenquyen);
			p[2] = new SqlParameter("@sTenviettat", entity.sTenviettat);
			p[3] = new SqlParameter("@sGhichu", entity.sGhichu);
            return p;
        }
        #endregion
       
    }
}